<%
    Users user = Trader.getUser(request.getParameter("uid"));
	String cat = request.getParameter("category");
	String Typ = request.getParameter("sample_type");
	int cat_i=Utils.strToInt(cat);
	wstrader.task.quality.SampleSent task = user.quality.samplesent;
	long focused_id=0;
	if (cat.compareTo("1")==0) 
	{
		wstrader.task.quality.SampleApproval task1 = user.quality.sampleapproval;
		task1.getRequest().setRequest(request);
		task1.getResponse().setResponse(response,out);
	
		if (!user.Authenticated()) {
			response.sendRedirect("logon.jsp");
			return;
		}
		((Tasks)task1.getOwner()).clearFocus();
		task1.setFocus(true);
		focused_id = task1.doTask();
	}	
	if (cat.compareTo("2")==0) 
	{
		wstrader.task.quality.SamplePreShipDelvy task1 = user.quality.samplepreshipdelvy;
		task1.getRequest().setRequest(request);
		task1.getResponse().setResponse(response,out);
	
		if (!user.Authenticated()) {
			response.sendRedirect("logon.jsp");
			return;
		}
		((Tasks)task1.getOwner()).clearFocus();
		task1.setFocus(true);
		focused_id = task1.doTask();
	}
		
	if (cat.compareTo("3")==0) 
	{
		wstrader.task.quality.SampleShipDelvy task1 = user.quality.sampleshipdelvy;
		task1.getRequest().setRequest(request);
		task1.getResponse().setResponse(response,out);
	
		if (!user.Authenticated()) {
			response.sendRedirect("logon.jsp");
			return;
		}
		((Tasks)task.getOwner()).clearFocus();
		task1.setFocus(true);
		focused_id = task1.doTask();
	}

	if (cat.compareTo("4")==0) 
	{
		wstrader.task.quality.SampleStock task1 = user.quality.samplestock;
		task1.getRequest().setRequest(request);
		task1.getResponse().setResponse(response,out);
	
		if (!user.Authenticated()) {
			response.sendRedirect("logon.jsp");
			return;
		}
		((Tasks)task1.getOwner()).clearFocus();
		task1.setFocus(true);
		focused_id = task1.doTask();		
	}
	
	if (cat.compareTo("5")==0) 
	{
		wstrader.task.quality.SampleRefTypeOffer task1 = user.quality.samplereftypeoffer;
		task1.getRequest().setRequest(request);
		task1.getResponse().setResponse(response,out);
	
		if (!user.Authenticated()) {
			response.sendRedirect("logon.jsp");
			return;
		}
		((Tasks)task1.getOwner()).clearFocus();
		task1.setFocus(true);
		focused_id = task1.doTask();		
	}
	Record rc   = task.getRecord("sample_details",focused_id);			
	Trader.window_width = "90%";	
	String newrec = request.getParameter("new_rec");	
%>
<%@include file="../header.jsp"%>
<style type="text/css">
<!--
.style6 {
	font-size: 12px;
	font-weight: bold;
	font-family: Arial;
}
.style7 {
	font-family: Arial;
	font-size: 12px;
}
.style14 {font-family: Arial}
-->
</style>

<script language="javascript">
function newrecord()
{
	var form = document.formMain;
	var value = "<%=task.GenRefNumber("QR AP",Utils.dateToStr(Utils.today()).substring(7),"quality_report")%>";	
	var value1 = "New Contract";
	if (addNewListItemById("sample_details",value1) < 0) return;	
	form.rec_id.value = "<%=task.getLastID("sample_details") + 1%>";
	form.sample_quality_ref_no.value = value;
	form.new_rec.value = "0";
	form.wn_ref_no.value ="";
	form.contract_ref_no.value = "";
	form.buyer_ref_no.value = "";
	form.contract_ton.value = "";
	form.sample_kgs.value="";
	setValue("sample_quality_ref_no",value);	
}

function doUpdate()
{
	var form = document.formMain;
	doTask(1);
}

function doListView()
{
	var form = document.formMain;
	if (form.type.value=="R")
	{
		form.action = "quality.samplereceived.jsp";
	}
	else
	{
		form.action = "quality.samplesent.jsp";	
	}	
	form.submit();
}
</script>
<form action="" method="post" name="formMain" id="formMain">
  <table width="100%"  border="0.5" cellspacing="0" cellpadding="0">
    <tr>
      <td colspan="3"><img src="images/samplequalitydts.jpg" width="400" height="30"></td>
      <td><input type="hidden" name="uid"        id="uid"       value="<%=user.getuid()%>">
        <input type="hidden" name="task_id"    id = "task_id"   value="0">
        <input name="type" type="hidden" id="type" value="<%=Typ%>">
        <input name="category" type="hidden" id="category" value="<%=cat%>">
        <input name="rec_id" type="hidden" id="rec_id" value="0">
        <input name="new_rec" type="hidden" id="new_rec" value="<%=newrec%>">
        <input name="sample_quality_ref_no" type="hidden" id="sample_quality_ref_no" style="width:162px"></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td colspan="5"><table width="100%"  border="1" cellspacing="0" cellpadding="0">
        <tr>
          <td width="12%" valign="top"><table width="100%"  border="0.5" cellspacing="0" cellpadding="0">
            <tr>
              <td height="29" align="center" bgcolor="#DDDDDD" class="style6">Ref. Number </td>
            </tr>
            <tr>
              <td>
			  <select name="sample_details" size="20" class="style2" id="sample_details" style="width:100%; border:0" onChange="doPost()">
                   <%@include file="include/QualityRefNoList.jsp"%>
              </select></td>
            </tr>
            <tr>
              <td>&nbsp;</td>
            </tr>
          </table></td>
          <td width="88%" align="left" valign="top"><table width="100%"  border="0.5" cellspacing="0" cellpadding="0">
            <tr>
              <td width="11%" height="30" align="right" class="style7">Type</td>
              <td width="1%">&nbsp;</td>
              <td colspan="2">
			  <select name="sample_type" id="sample_type" style="width:162px">
	  			<option value="S" >Sent</option>
			  	<option value="R" >Received</option>
				<%task.getResponse().setSelected("sample_type",Typ);%>				
			  </select>
			  </td>
              <td width="12%" align="right" class="style7">Tons</td>
              <td width="1%">&nbsp;</td>
              <td colspan="2"><input name="contract_ton" type="text" id="contract_ton" style="width:162px" value="<%=rc.getFloatValue("contract_ton")%>"></td>
            </tr>
            <tr>
              <td height="31" align="right" class="style7">Category</td>
              <td>&nbsp;</td>
              <td colspan="2">
			  <select name="sample_category_id" id="sample_category_id" style="width:162px">
			  	<option value="1" >Approval</option>
	  			<option value="2" >Pre-Shipment/Delivery</option>
	  			<option value="3" >Shipment/Delivery</option>
	  			<option value="4" >Stock</option>
	  			<option value="5" >Reference/Type/Offer</option>	
				<%task.getResponse().setSelected("sample_category_id",cat_i);%>									      
              </select>
			  </td>
              <td align="right" class="style7">Sample Kg</td>
              <td>&nbsp;</td>
              <td colspan="2"><input name="sample_kgs" type="text" id="sample_kgs" style="width:162px" value="<%=rc.getFloatValue("sample_kgs")%>">
			  </td>
            </tr>
            <tr>
              <td height="30" align="right" class="style7">WN No / Lot No </td>
              <td>&nbsp;</td>
              <td width="13%"><input name="wn_ref_no" type="text" id="buyer_ref_no23" style="width:162px" value="<%=rc.getString("wn_ref_no")%>"></td>
              <td width="15%" align="right">&nbsp;</td>
              <td align="right" class="style7">Controller</td>
              <td>&nbsp;</td>
              <td colspan="2"><select name="controller" id="controller" style="width:162px">
              </select>
			  </td>
            </tr>
            <tr>
              <td height="30" align="right" class="style7">Contract No. </td>
              <td>&nbsp;</td>
              <td><input name="contract_ref_no" type="text" id="contract_ref_no" style="width:162px" value="<%=rc.getString("contract_ref_no")%>"></td>
              <td align="right">&nbsp;</td>
              <td align="right" class="style7">Approved / Reject</td>
              <td>&nbsp;</td>
              <td width="13%"><select name="app_rej" id="select" style="width:162px">
                <option value="1">Approved</option>
                <option value="2" >Rejected</option>
              </select></td>
              <td width="34%">&nbsp;</td>
            </tr>
            <tr>
              <td height="30" align="right" class="style7">Buyer Ref No </td>
              <td>&nbsp;</td>
              <td colspan="2"><input name="buyer_ref_no" type="text" id="buyer_ref_no" style="width:162px" value="<%=rc.getString("buyer_ref_no")%>"></td>
              <td align="right" class="style7">Date</td>
              <td>&nbsp;</td>
              <td><input name="approved_reject_date" type="text" id="approved_reject_date" style="width:162px" value="<%=Utils.dateToStr(rc.getDateValue("approved_reject_date"))%>"></td>
              <td><img src="js/calendar.gif" width="20" height="20" onClick="popUpCalendar(this,'approved_reject_date','dd-mmm-yy');"></td>
            </tr>
            <tr>
              <td height="33" align="right" class="style7">Location</td>
              <td>&nbsp;</td>
              <td colspan="2">
			  <select name="warehouse_id" id="warehouse_id" style="width:162px">
			  	<%
					task.getResponse().setOption("warehouse_master","name");
					task.getResponse().setSelected("warehouse_id",rc.getIntValue("warehouse_id"));
				%>				  
              </select>
			  </td>
              <td align="right" class="style7">&nbsp;</td>
              <td>&nbsp;</td>
              <td colspan="2">&nbsp;</td>
            </tr>
            <tr>
              <td height="31" align="right" class="style7">Origin</td>
              <td>&nbsp;</td>
              <td colspan="2">
			  <select name="origin_id" id="origin_id" style="width:162px">
			  	<%
					task.getResponse().setOption("origin_master","name");
					task.getResponse().setSelected("origin_id",rc.getIntValue("origin_id"));
				%>	  
              </select>
			  </td>
              <td align="right">&nbsp;</td>
              <td>&nbsp;</td>
              <td colspan="2">&nbsp;</td>
              </tr>
            <tr>
              <td height="35" align="right" class="style7">Quality</td>
              <td>&nbsp;</td>
              <td colspan="2">
			  <select name="quality_id" id="quality_id" style="width:162px">
			  	<%
					task.getResponse().setOption("quality_master","name");
					task.getResponse().setSelected("quality_id",rc.getIntValue("quality_id"));
				%>	  
              </select>
			  </td>
              <td>&nbsp;</td>
              <td>&nbsp;</td>
              <td colspan="2">&nbsp;</td>
            </tr>
            <tr>
              <td height="33" align="right" class="style7">Grade</td>
              <td>&nbsp;</td>
              <td colspan="2">
			  <select name="grade_id" id="grade_id" style="width:162px">
			  	<%
					task.getResponse().setOption("grade_master","name");
					task.getResponse().setSelected("grade_id",rc.getIntValue("grade_id"));
				%>	  
              </select>
			  </td>
              <td>&nbsp;</td>
              <td>&nbsp;</td>
              <td colspan="2">&nbsp;</td>
            </tr>
            <tr>
              <td height="33" align="right" class="style7">Remarks</td>
              <td>&nbsp;</td>
              <td colspan="6">&nbsp;</td>
              </tr>
            <tr>
              <td height="28" align="right" class="style7">Sample Ref </td>
              <td>&nbsp;</td>
              <td colspan="6"><select name="sample_master_id" id="sample_master_id" style="width:162px">
                <%
					task.getResponse().setOption("sample_master","ref_number");
					if (newrec==null) newrec="0";
					if (newrec.compareTo("1")==0)
					{
						task.getResponse().setSelected("sample_master_id",focused_id);
					}
					else
					{
						task.getResponse().setSelected("sample_master_id",rc.getIntValue("sample_master_id"));					
					}
				%>
              </select></td>
            </tr>
			<%
				rc.close();
				if (focused_id == 0)
				{
					rc   = task.getRecord("quality_report",focused_id);				
				}
				else
				{
					rc   = task.getRecord("quality_report",task.getQualityId(focused_id));				
				}	
			%>
            <tr>
              <td>&nbsp;</td>
              <td>&nbsp;</td>
              <td colspan="2">&nbsp;</td>
              <td>&nbsp;</td>
              <td>&nbsp;</td>
              <td colspan="2">&nbsp;</td>
            </tr>
            <tr>
              <td align="right" class="style7">Screen</td>
              <td>&nbsp;</td>
              <td colspan="6"><table width="84%"  border="0.5" cellspacing="0" cellpadding="0">
                <tr bgcolor="#DDDDDD">
                  <td width="9%" align="center" class="style6">Sc20+ </td>
                  <td width="9%" align="center" class="style6">Sc19</td>
                  <td width="9%" align="center" class="style6">Sc18</td>
                  <td width="9%" align="center" class="style6">Sc17</td>
                  <td width="9%" align="center" class="style6">Sc16</td>
                  <td width="9%" align="center" class="style6">Sc15</td>
                  <td width="9%" align="center" class="style6">Sc14</td>
                  <td width="9%" align="center" class="style6">Sc13</td>
                  <td width="10%" align="center" class="style6">Sc12</td>
                  <td width="18%" align="center" class="style6">Sc12-</td>
                </tr>
                <tr>
                  <td><input name="above_sc20" type="text" id="above_sc20" style="width:80px" value="<%=rc.getFloatValue("sc20")%>"></td>
                  <td><input name="sc19" type="text" id="sc19" style="width:80px" value="<%=Utils.numberToStr(rc.getFloatValue("sc19"),2)%>"></td>
                  <td><input name="sc18" type="text" id="sc18" style="width:80px" value="<%=Utils.numberToStr(rc.getFloatValue("sc18"),2)%>"></td>
                  <td><input name="sc17" type="text" id="sc17" style="width:80px" value="<%=Utils.numberToStr(rc.getFloatValue("sc17"),2)%>"></td>
                  <td><input name="sc16" type="text" id="sc16" style="width:80px" value="<%=Utils.numberToStr(rc.getFloatValue("sc16"),2)%>"></td>
                  <td><input name="sc15" type="text" id="sc15" style="width:80px" value="<%=Utils.numberToStr(rc.getFloatValue("sc15"),2)%>"></td>
                  <td><input name="sc14" type="text" id="sc14" style="width:80px" value="<%=Utils.numberToStr(rc.getFloatValue("sc14"),2)%>"></td>
                  <td><input name="sc13" type="text" id="sc13" style="width:80px" value="<%=Utils.numberToStr(rc.getFloatValue("sc13"),2)%>"></td>
                  <td><input name="sc12" type="text" id="sc12" style="width:80px" value="<%=Utils.numberToStr(rc.getFloatValue("sc12"),2)%>"></td>
                  <td><input name="below_sc12" type="text" id="below_sc12" style="width:80px" value="<%=Utils.numberToStr(rc.getFloatValue("below_sc12"),2)%>"></td>
                </tr>
              </table></td>
              </tr>
            <tr>
              <td>&nbsp;</td>
              <td>&nbsp;</td>
              <td colspan="2">&nbsp;</td>
              <td>&nbsp;</td>
              <td>&nbsp;</td>
              <td colspan="2">&nbsp;</td>
            </tr>
            <tr>
              <td align="right" class="style7">Defects</td>
              <td>&nbsp;</td>
              <td colspan="6"><table width="33%"  border="0.5" cellspacing="0" cellpadding="0">
                <tr bgcolor="#DDDDDD">
                  <td width="17%" align="center" class="style6">Black</td>
                  <td width="17%" align="center" class="style6">Brown</td>
                  <td width="17%" align="center" class="style6">FM</td>
                  <td width="49%" align="center" class="style6">Broken</td>
                </tr>
                <tr>
                  <td><input name="black" type="text" id="black" style="width:80px" value="<%=Utils.numberToStr(rc.getFloatValue("black"),2)%>"></td>
                  <td><input name="brown" type="text" id="brown" style="width:80px" value="<%=Utils.numberToStr(rc.getFloatValue("brown"),2)%>"></td>
                  <td><input name="foreign_matter" type="text" id="foreign_matter" style="width:80px" value="<%=Utils.numberToStr(rc.getFloatValue("foreign_matter"),2)%>"></td>
                  <td><input name="broken" type="text" id="broken" style="width:80px" value="<%=Utils.numberToStr(rc.getFloatValue("broken"),2)%>"></td>
                </tr>
              </table></td>
              </tr>
            <tr>
              <td>&nbsp;</td>
              <td>&nbsp;</td>
              <td colspan="2">&nbsp;</td>
              <td>&nbsp;</td>
              <td>&nbsp;</td>
              <td colspan="2">&nbsp;</td>
            </tr>
            <tr>
              <td>&nbsp;</td>
              <td><img src="images/update.gif" width="15" height="15" onClick="doUpdate();"></td>
              <td colspan="2">&nbsp;</td>
              <td>&nbsp;</td>
              <td>&nbsp;</td>
              <td colspan="2">&nbsp;</td>
            </tr>
            <tr>
              <td>&nbsp;</td>
              <td>&nbsp;</td>
              <td colspan="2">&nbsp;</td>
              <td>&nbsp;</td>
              <td>&nbsp;</td>
              <td colspan="2">&nbsp;</td>
            </tr>
            <tr>
              <td>&nbsp;</td>
              <td>&nbsp;</td>
              <td colspan="2">&nbsp;</td>
              <td>&nbsp;</td>
              <td>&nbsp;</td>
              <td colspan="2">&nbsp;</td>
            </tr>
          </table></td>
        </tr>
      </table></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td align="right"><img src="images/listview.jpg" width="55" height="18" onClick="doListView()"></td>
    </tr>
  </table>
  
<% if (newrec.compareTo("1")==0)
	{ 
%>	  
<script>
	newrecord();
</script>
<%
	}
%>
  
</form>
<%@include file="../footer.jsp"%>
